<html>
<head>
 <!--
    CPAINT (Cross-Platform Asynchronous INterface Toolkit) - Version 2

    http://sf.net/projects/cpaint
    
    released under the terms of the GPL
    see http://www.fsf.org/licensing/licenses/gpl.txt for details

    authors:  Paul Sullivan <wiley14@gmail.com>, Dominique Stender <dstender@st-webdevelopment.de>
    Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint
  //-->
	<title>cpaint2 response types test</title>
	<script type="text/javascript; e4x=1" src="../../cpaint2.inc.js"></script>
	<script type="text/javascript; e4x=1">
    var cp = new cpaint();
    cp.set_response_type('text');
    cp.set_debug(-1);
	
    function ping() {
      switch (document.getElementById('typeSelect').options[document.getElementById('typeSelect').selectedIndex].value) {
      
        case 'TEXT':
          cp.set_response_type('text');
          break;
          
        case 'OBJECT':
          cp.set_response_type('object');
          break;
          
        case 'XML':
          cp.set_response_type('xml');
          break;
          
        case 'E4X':
          cp.set_response_type('e4x');
          break;

        case 'JSON':
          cp.set_response_type('json');
          break;
      }

      document.getElementsByTagName('body').item(0).style.cursor = 'wait';
      
      cp.call('types.php', 'multitype', response);
      return false;
    }

    function response(result, text_result) {
      switch (document.getElementById('typeSelect').options[document.getElementById('typeSelect').selectedIndex].value) {
      
        case 'TEXT':
          text_response(result);
          break;
          
        case 'OBJECT':
          object_response(result);
          break;
          
        case 'XML':
          xml_response(result);
          break;
          
        case 'E4X':
          e4x_response(result);
          break;
          
        case 'JSON':
          json_response(result);
          break;
      }

      document.getElementsByTagName('body').item(0).style.cursor = 'auto';
		}
    
    function text_response(result) {
      document.getElementById('response').innerHTML = 'text response:<br />' + result;
    }
    
    function object_response(result) {
      var i     = 0;
      var disp  = 'object response:<br />';
      
      for (i = 0; i < result.ajaxResponse[0].list[0].item.length; i++) {
        disp += result.ajaxResponse[0].list[0].item[i].data + "<br />\n";
      }
      
      document.getElementById('response').innerHTML = disp;
    }
    
    function xml_response(result) {
      var i     = 0;
      var items = result.getElementsByTagName('item');
      var disp  = 'xml response:<br />';
      
      for (i = 0; i < items.length; i++) {
        disp += items[i].firstChild.nodeValue + "<br />\n";
      }
      
      document.getElementById('response').innerHTML = disp;
    }
    
    function e4x_response(result) {
      var item = 0;
      var disp = 'E4X response:<br />';
      
      for each (item in result..item) {
        disp += item + '<br />';
      }
      
      document.getElementById('response').innerHTML = disp;
    }
    
    function json_response(result) {
      var i    = 0;
      var disp = 'JSON response:<br />';
      
      for (i = 0; i < result.list[0].item.length; i++) {
        disp += result.list[0].item[i].data + '<br />';
      }
      
      document.getElementById('response').innerHTML = disp;
    }
	</script>
</head>
<body>
	This script verifies that the following response types are callable by CPAINT:<br />
  <ol>
    <li>TEXT</li>
    <li>OBJECT</li>
    <li>XML</li>
    <li>E4X (Firefox 1.5 only)</li>
    <li>JSON</li>
  </ol>
	<br />
	<form action="#" onSubmit="return ping()">
    <select id="typeSelect">
      <option value="TEXT" selected>TEXT</option>
      <option value="OBJECT">OBJECT</option>
      <option value="XML">XML</option>
      <option value="E4X">E4X</option>
      <option value="JSON">JSON</option>
    </select>
		<input type="submit" value="test response type" />
	</form>
	<div id="response"></div>
</body>
</html>
